import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Temp {

	public static void main(String[] args) {
		String text = "0";
		String patText = "(^[^\\w\\s\\(\\)\\[\\]\\{\\}]{1,2})(MOD|POW)"; 
		Pattern pat = Pattern.compile(patText);
		Matcher matcher = pat.matcher(text);
		Scanner scan = new Scanner(System.in);
		text = scan.next();
		do {
			matcher = pat.matcher(text);
			if(matcher.find()){
			String temp = text.substring(matcher.start(), matcher.end());
			//System.out.println(temp);
			System.out.println(matcher.group(matcher.groupCount()));
			}
			text = scan.next();
			
		}while (!text.equals("out"));	
	}
	
//		HashMap<String,Integer> map = new HashMap<String, Integer>();
//		map.put("[//[].*", 8);
//		if(map.get("[dhdhdh")==null) {
//			System.out.println("no");
//		}else{
//			System.out.println("yes");
//		}
		
	

}